<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="90px"
  (onSearch)="queryData($event)"
  (onReset)="resetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-2">
  <div class="operation-wrap">
    <button
      *ngIf="permission.userPermission.has('secondCoupon:add')"
      nz-button
      nzType="primary"
      (click)="jumpPage(0)"
    >新增优惠券</button>
  </div>

  <div class="pagination-wrap-position table-wrap p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="180px">券码</th>
          <th nzAlign="center" nzWidth="220px">优惠券名称</th>
          <th nzAlign="center" nzWidth="220px">优惠内容</th>
          <th nzAlign="center" nzWidth="220px">备注</th>
          <th nzAlign="center" nzWidth="120px">已领取</th>
          <th nzAlign="center" nzWidth="120px">剩余</th>
          <th nzAlign="center" nzWidth="120px">类型</th>
          <th nzAlign="center" nzWidth="120px">状态</th>
          <th nzAlign="center" nzWidth="380px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 券码 -->
          <td nzAlign="center">{{ data.no || '-' }}</td>
          <!-- 优惠券名称 -->
          <td nzAlign="center">{{ data.name || '-' }}</td>
          <!-- 优惠内容 -->
          <td nzAlign="center">{{ data.useDesc || '-' }}</td>
          <!-- 备注 -->
          <td nzAlign="center">{{ data.remark || '-' }}</td>
          <!-- 已领取 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': '#2e8ff4'}">
              {{ data.numberReceived || '0' }}
            </span>
          </td>
          <!-- 剩余 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.remainingNumber < 1000 ? '#ff0052' : ''}">
              {{ data.remainingNumber || '0' }}
            </span>
          </td>
          <!-- 类型 -->
          <td nzAlign="center">
            {{ data.type == 1 ? '满减券' : data.type == 2 ? '折扣券' : '随机券' }}
          </td>
          <!-- 状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.status | sencondCouponStatus: 'color'}">
              {{ data.status | sencondCouponStatus: 'label' }}
            </span>
          </td>
          <!-- 操作 -->
          <td nzAlign="center" nzRight class="opreation-btns">
            <a
              nz-button
              nzSize="small"
              nzType="link"
              (click)="jumpPage(2, data)"
            >查看</a>

            <a
              *ngIf="permission.userPermission.has('secondCoupon:edit')"
              nz-button
              nzSize="small"
              nzType="link"
              (click)="jumpPage(1, data)"
            >编辑</a>

            <a
              *ngIf="permission.userPermission.has('secondCoupon:add')"
              nz-button
              nzSize="small"
              nzType="link"
              (click)="jumpPage(3, data)"
            >复制</a>

            <a
              *ngIf="data.status === 6 && permission.userPermission.has('secondCoupon:examine')"
              nz-button
              nzSize="small"
              nzType="link"
              (click)="showExamineModal(data)"
            >审核</a>

            <a
              *ngIf="[1, 2].includes(data.status) && permission.userPermission.has('secondCoupon:stop')"
              nz-button
              nzSize="small"
              nzType="link"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确定停止该优惠券的发放?"
              (nzOnConfirm)="stopItem(data)"
            >停止</a>

            <a
              *ngIf="[1, 5].includes(data.status) && permission.userPermission.has('secondCoupon:delete')"
              nz-button
              nzSize="small"
              nzType="link"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认删除?"
              (nzOnConfirm)="deleteItem(data)"
            >删除</a>

            <a
              *ngIf="[1, 2].includes(data.status) && permission.userPermission.has('secondCoupon:manualRelease')"
              nz-button
              nzSize="small"
              nzType="link"
              (click)="showCouponModal(data)"
            >手动发放</a>

            <a
              *ngIf="[1, 2].includes(data.status)"
              nz-button
              nzSize="small"
              nzType="link"
              nz-popconfirm
              nzPopconfirmTitle="确认生成商品标签?"
              (nzOnConfirm)="generateGoodLable(data)"
            >生成商品标签</a>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- S 审核Modal -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isExamineVisible"
  [nzTitle]="'审核'"
  (nzOnCancel)="isExamineVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <nz-textarea-count [nzMaxCharacterCount]="100">
        <textarea rows="4" nz-input placeholder="请输入审核意见" [(ngModel)]="examineParams.remark"></textarea>
      </nz-textarea-count>
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="primary" (click)="subExamine(1)">审核通过</button>
        <button nz-button nzType="primary" nzDanger (click)="subExamine(7)">审核不通过</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- E 审核Modal -->

<!-- S 手动发放 -->
<manual-release-modal
  [(ngModel)]="releaseVisible"
  [couponCode]="opreaItem?.no"
  [modalTitle]="'手动发放优惠券'"
  (submitManual)="submitManual($event)"
></manual-release-modal>
<!-- E 手动发放 -->